var BASE_URL = 'https://api.achiguo.com' // 阿里云地址
// var BASE_URL = 'http://218.2.230.37:5324' // 阿高本机地址

// var requestHandler = {
//   data: {}, // 参数
//   url: '' // 具体接口地址

// }
const network = {
  GET: (requestHandler) => {
    return request('GET', requestHandler)
  },
  POST: (requestHandler) => {
    return request('POST', requestHandler)
  },
  DELETE: (requestHandler) => {
    return request('DELETE', requestHandler)
  }
}

const request = (method, requestHandler) => {
  // 注意：可以对params加密等处理
  var params = requestHandler.data
  var uri = requestHandler.url
  return new Promise(function (resolve, reject) {
    wx.request({
      url: BASE_URL + uri,
      data: params,
      method: method, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: { thirdSession: wx.getStorageSync('3rdSession')}, // 设置请求的 header
      success: function (res) {
        // 注意：可以对参数解密等处理
        resolve(res)
      },
      fail: function (error) {
        reject(error)
      }
    })
  })
}

export default network
